<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%edivi_order_ypbl}}".
 *
 * @property int $id
 * @property int $edivi_credit_order_id
 * @property int $created_at
 * @property string $material_code 材料编码
 * @property int $materials_type 材料下载方式
 * @property int $download_mode
 *
 * @property EdiviCreditOrderUsersPics[] $ediviCreditOrderUsersPics
 * @property EdiviCreditOrder $ediviCreditOrder
 */
class EdiviOrderYpbl extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%edivi_order_ypbl}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['edivi_credit_order_id', 'created_at', 'material_code'], 'required'],
            [['edivi_credit_order_id', 'created_at', 'materials_type', 'download_mode'], 'integer'],
            [['material_code'], 'string', 'max' => 30],
            [['edivi_credit_order_id'], 'exist', 'skipOnError' => true, 'targetClass' => EdiviCreditOrder::className(), 'targetAttribute' => ['edivi_credit_order_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'edivi_credit_order_id' => Yii::t('app', 'Edivi Credit Order ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'material_code' => Yii::t('app', '材料编码'),
            'materials_type' => Yii::t('app', '材料下载方式'),
            'download_mode' => Yii::t('app', 'Download Mode'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEdiviCreditOrderUsersPics()
    {
        return $this->hasMany(EdiviCreditOrderUsersPics::className(), ['edivi_yp_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getEdiviCreditOrder()
    {
        return $this->hasOne(EdiviCreditOrder::className(), ['id' => 'edivi_credit_order_id']);
    }
}
